<?php
namespace app\common\exception;

use Exception;
use think\exception\Handle;
use think\exception\HttpException;
// use think\exception\ValidateException;
use app\common\exception\BaseException;

class Http extends Handle
{
    public function render(Exception $e)
    {
        // 参数验证错误
        if ($e instanceof BaseException) {
            $data = [
                'errorCode'=> $e->errorCode,
                'msg'=> $e->msg
            ];
            return json($data, 422);
        }

        // 请求异常
        if ($e instanceof HttpException) {
            // dump($e);die;
            $data = [
                'errorCode'=> $e->getStatusCode(),
                'msg'=> '请求错误，请检查请求方式是否有误'
            ];
            return json($data,$e->getStatusCode());
        }

        // 其他错误交给系统处理
        return parent::render($e);
    }

}